<?php

namespace App\ApiBackend\Workbench;

use App\Http\Controllers\ApiBaseController;
use Illuminate\Support\Facades\DB;


/**
 * 项目统计
 */
class Statistic extends ApiBaseController
{
  /**
   * 参数检查
   */
  protected function check(): void
  {

  }

  /**
   * 业务主体
   */
  protected function service(): void
  {

    $groupData = [];
    // dump(request()->user()->roleId);
    $roleId = request()->user()->roleId;
    $timeCur = time();
    //本周一
    $weekdayCur = date('w', $timeCur);
    $monday = date('Y-m-d', $timeCur - ($weekdayCur - 1) * 86400);

    switch ($roleId) {
      default:
        $groupData[] = [
          "title" => '商品数',
          "icon" => 'material-symbols:database-outline',
          "color" => 'green',
          "action" => '本周',
          "value" => mt_rand(1, 99),// DB::table("goods")->where('createTime', '>', $monday)->where('status', 1)->count(),
          "total" => mt_rand(1, 99),// DB::table("goods")->where('status', 1)->count(),
        ];
        $orderStatusArr = [1, 2, 8];
        $groupData[] = [
          "title" => '订单数',
          "icon" => 'material-symbols:order-approve-outline-rounded',
          "color" => 'green',
          "action" => '本周',
          "value" => mt_rand(1, 99),//DB::table("order")->where('createTime', '>', $monday)->whereIn('status', $orderStatusArr)->count(),
          "total" => mt_rand(1, 99),//DB::table("order")->whereIn('status', $orderStatusArr)->count(),
        ];
        $memberStatusArr = [1];
        $groupData[] = [
          "title" => '会员数',
          "icon" => 'material-symbols:account-box-outline',
          "color" => 'green',
          "action" => '本周',
          "value" => mt_rand(1, 99),//DB::table("user")->where('createTime', '>', $monday)->whereIn('status', $memberStatusArr)->count(),
          "total" => mt_rand(1, 99),//DB::table("user")->whereIn('status', $memberStatusArr)->count(),
        ];
        $articleStatusArr = [1];
        $groupData[] = [
          "title" => '文章数',
          "icon" => 'ant-design:file-outlined',
          "color" => 'green',
          "action" => '本周',
          "value" => mt_rand(1, 99),//DB::table("cms_article")->where('createTime', '>', $monday)->whereIn('status', $memberStatusArr)->count(),
          "total" => mt_rand(1, 99),//DB::table("cms_article")->whereIn('status', $memberStatusArr)->count(),
        ];
        break;

    }

    $this->result["data"] = $groupData;
    return;
  }
}
